package cn.imnaer.service.rpc.scenic.dao;

import cn.imnaer.database.BaseDao;
import cn.imnaer.database.MatchConst;
import cn.imnaer.database.define.DBConstant;
import cn.imnaer.service.persistence.model.Scenic;
import cn.imnaer.service.persistence.model.consts.SCENIC;
import cn.imnaer.service.rest.view.model.BasicScenic;
import cn.imnaer.service.rest.view.model.Place;

import org.bson.BSONObject;
import org.bson.BasicBSONObject;

import java.util.ArrayList;
import java.util.List;

public class ScenicDaoImpl extends BaseDao<Scenic> {
    private static ScenicDaoImpl instance = new ScenicDaoImpl();

    private ScenicDaoImpl() {
       
    }

    public static ScenicDaoImpl getInstance() {
        return instance;
    }

    public List<Place> search(String keywords) {
    	String[] selector=new String[]{SCENIC.scenicName,SCENIC.scenicId,SCENIC.location};
		BSONObject order=new  BasicBSONObject();
		order.put("titleSize", -1);
		List<BSONObject>  bsonObjects=this.search(keywords, SCENIC.scenicName, selector, order, false);
        List<Place> placeList=new ArrayList<>();
		try {
            for (BSONObject bsonObject : bsonObjects) {
                BasicScenic scenic = bsonObject.as(BasicScenic.class);
                Place place = new Place();
                place.setAttribute(scenic);
                placeList.add(place);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return placeList;
    }

	@Override
	protected String getDbSpaceName() {
		return DBConstant.SPACE.SCENIC_INFO_SPACE;
	}

	@Override
	protected String getDbCollectionName() {
		return DBConstant.COLLECTION.SCENIC_INFO_COLLECTION;
	}

	@Override
	protected String getPrimaryKey() {
		return SCENIC.scenicId;
	}

		
}
